package com.zjw.zy.ext

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import java.io.ByteArrayOutputStream
import java.io.IOException


fun Bitmap.toByteArray(): ByteArray {
    val out = ByteArrayOutputStream()
    this.compress(Bitmap.CompressFormat.PNG, 100, out)

    val bytes = out.toByteArray()
    try {
        out.close()
    } catch (ignore: IOException) {

    }
    return bytes
}


fun fromByteArray(bytes: ByteArray): Bitmap {
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
}